package cn.yeziji.forum.utils;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 线程池管理工具类
 *
 * @author hwy
 * @since 2023/07/29 13:32
 **/
public class ThreadPoolUtils {
  public static final String CUSTOM = "customExecutor";
  public static final String IO = "ioTaskExecutor";
  public static final String CPU = "cpuTaskExecutor";

  public static ThreadPoolTaskExecutor getIoThreadPool() {
    return getThreadPool(IO);
  }

  public static ThreadPoolTaskExecutor getCpuThreadPool() {
    return getThreadPool(CPU);
  }

  public static ThreadPoolTaskExecutor getCustomThreadPool() {
    return getThreadPool(CUSTOM);
  }

  public static ThreadPoolTaskExecutor getThreadPool(final String poolName) {
    return SpringUtils.getBean(poolName);
  }
}
